package com.fire.control.system.module.common.controller.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.fire.control.system.entity.DeviceType;
import com.fire.control.system.module.common.service.AreaService;
import com.fire.control.system.module.device.service.DeviceTypeService;
import com.fire.control.system.standard.BusinessInterfaceStandard;
import com.fire.control.system.statics.Status_Duty;
import com.fire.control.system.statics.Status_Message;
import com.fire.control.system.statics.Status_Online;
import com.fire.control.system.statics.Status_Warning;
import com.fire.control.system.statics.Type_Company;
import com.fire.control.system.statics.Type_MessageTarget;
import com.fire.control.system.statics.Type_MsgScope;
import com.fire.control.system.statics.Type_Resource;
import com.fire.control.system.statics.Type_Role;
import com.fire.control.system.statics.Type_Solution;
import com.fire.control.system.statics.Type_SureWarning;
import com.fire.control.system.statics.Type_Upgrade;
import com.fire.control.system.statics.Type_User;
import com.fire.control.system.statics.Type_Warning;
import com.fire.control.system.support.protocol.comman.RequestProtocol;
import com.fire.control.system.support.protocol.comman.ResponseJsonProtocol;
import com.fire.control.system.support.protocol.comman.ResponseProtocol;
import com.fire.control.system.support.protocol.common.SelectRequestProtocol;
import com.fire.control.system.support.util.StaticValue;

@RestController
@RequestMapping("public")
public class PublicController implements BusinessInterfaceStandard<RequestProtocol, ResponseProtocol>{
	
	@Autowired private AreaService areaService;
	@Autowired private DeviceTypeService deviceTypeService;
	
	@RequestMapping(value = "/getDeviceType", method = RequestMethod.POST)
	public ResponseProtocol getDeviceType(SelectRequestProtocol request) {
		ResponseJsonProtocol protocol = new ResponseJsonProtocol();
		Map<String, Object> map = new HashMap<String, Object>();
		List<Map<String,Object>> list = new ArrayList<>();
		List<DeviceType> deviceTypes = deviceTypeService.getDeviceTypeList();
		for (DeviceType deviceType : deviceTypes) {
			Map<String,Object> map2 = new HashMap<String,Object>();
			map2.put("id",deviceType.getId());
			map2.put("name",deviceType.getName());
			list.add(map2);
		}
		map.put("deviceType", list);
		protocol.setData(map);
		return protocol;
	}
	
	/**
	 * @author: xiechengguang 
	 * @Title: getRegion   
	 * @Description: 获取省市区 下面的 设备组  
	 * @param:        
	 * @return: ResponseProtocol      
	 * @throws
	 */
	@RequestMapping(value = "/getRegion", method = RequestMethod.POST)
	public ResponseProtocol getRegion(SelectRequestProtocol request) {
		return areaService.getRegion(request);
	}
	
	/**
	* @Title: wssServer
	* @Description: TODO(soketio服务地址)
	* @author wanbo
	* @date  2017年6月29日 下午12:54:41
	* @return
	*/
	@RequestMapping(value="wssServer", method = RequestMethod.POST)
	public ResponseProtocol	wssServer(){
		ResponseJsonProtocol protocol = new ResponseJsonProtocol();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("wssServer", StaticValue.wss_server_domain);
		protocol.setData(map);
		return protocol;
	}
	
	/**
	 * @author: zhanhongtan
	* @Title: getTypeUserForJson 
	* @Description: TODO(用户类型) 
	* @param @return    设定文件 
	* @return ResponseProtocol    返回类型 
	* @throws
	 */
	@RequestMapping(value="/getTypeUserForJson", method = RequestMethod.POST)
	public ResponseProtocol getTypeUserForJson(){
		
		List<Map<String,Object>> list = new ArrayList<>();
		for(Type_User typeUser:Type_User.values()){
			Map<String,Object> map = new HashMap<>();
			map.put("key",typeUser.name());
			map.put("val",typeUser.getText());
			list.add(map);
		}
		ResponseProtocol respProtocol =  new ResponseJsonProtocol();
		respProtocol.setData(list);
		return respProtocol;
	}
	/**
	 * @author: zhanhongtan
	* @Title: getTypeGradeForJson 
	* @Description: TODO(升级模式) 
	* @param @return    设定文件 
	* @return ResponseProtocol    返回类型 
	* @throws
	 */
	@RequestMapping(value="/getTypeGradeForJson", method = RequestMethod.POST)
	public ResponseProtocol getTypeGradeForJson(){
		
		List<Map<String,Object>> list = new ArrayList<>();
		for(Type_Upgrade typeUpgrade:Type_Upgrade.values()){
			Map<String,Object> map = new HashMap<>();
			map.put("key",typeUpgrade.name());
			map.put("val",typeUpgrade.getText());
			list.add(map);
		}
		ResponseProtocol respProtocol =  new ResponseJsonProtocol();
		respProtocol.setData(list);
		return respProtocol;
	}
	/**
	 * @author: zhanhongtan
	* @Title: getTypeSureWarningeForJson 
	* @Description: TODO(报警确认类型) 
	* @param @return    设定文件 
	* @return ResponseProtocol    返回类型 
	* @throws
	 */
	@RequestMapping(value="/getTypeSureWarningeForJson", method = RequestMethod.POST)
	public ResponseProtocol getTypeSureWarningeForJson(){
		
		List<Map<String,Object>> list = new ArrayList<>();
		for(Type_SureWarning typeSureWarninge:Type_SureWarning.values()){
			Map<String,Object> map = new HashMap<>();
			map.put("key",typeSureWarninge.name());
			map.put("val",typeSureWarninge.getText());
			list.add(map);
		}
		ResponseProtocol respProtocol =  new ResponseJsonProtocol();
		respProtocol.setData(list);
		return respProtocol;
	}
	/**
	 * @author: zhanhongtan
	* @Title: getTypeSolutionForJson 
	* @Description: TODO(报警解决方案) 
	* @param @return    设定文件 
	* @return ResponseProtocol    返回类型 
	* @throws
	 */
	@RequestMapping(value="/getTypeSolutionForJson", method = RequestMethod.POST)
	public ResponseProtocol getTypeSolutionForJson(){
		
		List<Map<String,Object>> list = new ArrayList<>();
		for(Type_Solution typeSolution:Type_Solution.values()){
			Map<String,Object> map = new HashMap<>();
			map.put("key",typeSolution.name());
			map.put("val",typeSolution.getText());
			list.add(map);
		}
		ResponseProtocol respProtocol =  new ResponseJsonProtocol();
		respProtocol.setData(list);
		return respProtocol;
	}
	/**
	 * @author: zhanhongtan
	* @Title: getTypeRoleForJson 
	* @Description: TODO(角色类型) 
	* @param @return    设定文件 
	* @return ResponseProtocol    返回类型 
	* @throws
	 */
	@RequestMapping(value="/getTypeRoleForJson", method = RequestMethod.POST)
	public ResponseProtocol getTypeRoleForJson(){
		
		List<Map<String,Object>> list = new ArrayList<>();
		for(Type_Role typeRole:Type_Role.values()){
			Map<String,Object> map = new HashMap<>();
			map.put("key",typeRole.name());
			map.put("val",typeRole.getText());
			map.put("id",typeRole.getId());
			list.add(map);
		}
		ResponseProtocol respProtocol =  new ResponseJsonProtocol();
		respProtocol.setData(list);
		return respProtocol;
	}
	/**
	 * @author: zhanhongtan
	* @Title: getTypeResourceForJson 
	* @Description: TODO(资源菜单类型) 
	* @param @return    设定文件 
	* @return ResponseProtocol    返回类型 
	* @throws
	 */
	@RequestMapping(value="/getTypeResourceForJson", method = RequestMethod.POST)
	public ResponseProtocol getTypeResourceForJson(){
		
		List<Map<String,Object>> list = new ArrayList<>();
		for(Type_Resource typeResource:Type_Resource.values()){
			Map<String,Object> map = new HashMap<>();
			map.put("key",typeResource.name());
			map.put("val",typeResource.getText());
			list.add(map);
		}
		ResponseProtocol respProtocol =  new ResponseJsonProtocol();
		respProtocol.setData(list);
		return respProtocol;
	}
	/**
	 * @author: zhanhongtan
	* @Title: getTypeMsgScopeForJson 
	* @Description: TODO(发送范围) 
	* @param @return    设定文件 
	* @return ResponseProtocol    返回类型 
	* @throws
	 */
	@RequestMapping(value="/getTypeMsgScopeForJson", method = RequestMethod.POST)
	public ResponseProtocol getTypeMsgScopeForJson(){
		
		List<Map<String,Object>> list = new ArrayList<>();
		for(Type_MsgScope typeMsgScope:Type_MsgScope.values()){
			Map<String,Object> map = new HashMap<>();
			map.put("key",typeMsgScope.name());
			map.put("val",typeMsgScope.getText());
			list.add(map);
		}
		
		ResponseProtocol respProtocol =  new ResponseJsonProtocol();
		respProtocol.setData(list);
		return respProtocol;
	}
	/**
	 * @author: zhanhongtan
	* @Title: getTypeMessageTargetForJson 
	* @Description: TODO(发送消息类型) 
	* @param @return    设定文件 
	* @return ResponseProtocol    返回类型 
	* @throws
	 */
	@RequestMapping(value="/getTypeMessageTargetForJson", method = RequestMethod.POST)
	public ResponseProtocol getTypeMessageTargetForJson(){
		
		List<Map<String,Object>> list = new ArrayList<>();
		for(Type_MessageTarget typeMessageTarget:Type_MessageTarget.values()){
			Map<String,Object> map = new HashMap<>();
			map.put("key",typeMessageTarget.name());
			map.put("val",typeMessageTarget.getText());
			list.add(map);
		}
		
		ResponseProtocol respProtocol =  new ResponseJsonProtocol();
		respProtocol.setData(list);
		return respProtocol;
	}
	/**
	 *@author: zhanhongtan 
	* @Title: getTypeCompanyForJson 
	* @Description: TODO(机构类型) 
	* @param @return    设定文件 
	* @return ResponseProtocol    返回类型 
	* @throws
	 */
	@RequestMapping(value="/getTypeCompanyForJson", method = RequestMethod.POST)
	public ResponseProtocol getTypeCompanyForJson(){
		
		List<Map<String,Object>> list = new ArrayList<>();
		for(Type_Company typeCompany:Type_Company.values()){
			Map<String,Object> map = new HashMap<>();
			map.put("key",typeCompany.name());
			map.put("val",typeCompany.getText());
			list.add(map);
		}
		
		ResponseProtocol respProtocol =  new ResponseJsonProtocol();
		respProtocol.setData(list);
		return respProtocol;
	}
	/**
	 *@author: zhanhongtan 
	* @Title: getStatusWarningForJson 
	* @Description: TODO(报警状态) 
	* @param @return    设定文件 
	* @return ResponseProtocol    返回类型 
	* @throws
	 */
	@RequestMapping(value="/getStatusWarningForJson", method = RequestMethod.POST)
	public ResponseProtocol getStatusWarningForJson(){
		
		List<Map<String,Object>> list = new ArrayList<>();
		for(Status_Warning statusWarning:Status_Warning.values()){
			Map<String,Object> map = new HashMap<>();
			map.put("key",statusWarning.name());
			map.put("val",statusWarning.getText());
			list.add(map);
		}
		
		ResponseProtocol respProtocol =  new ResponseJsonProtocol();
		respProtocol.setData(list);
		return respProtocol;
	}
	/**
	 *@author: zhanhongtan 
	* @Title: getStatusOnlineForJson 
	* @Description: TODO(设备状态) 
	* @param @return    设定文件 
	* @return ResponseProtocol    返回类型 
	* @throws
	 */
	@RequestMapping(value="/getStatusOnlineForJson", method = RequestMethod.POST)
	public ResponseProtocol getStatusOnlineForJson(){
		
		List<Map<String,Object>> list = new ArrayList<>();
		for(Status_Online statusOnline:Status_Online.values()){
			Map<String,Object> map = new HashMap<>();
			map.put("key",statusOnline.name());
			map.put("val",statusOnline.getText());
			list.add(map);
		}
		
		ResponseProtocol respProtocol =  new ResponseJsonProtocol();
		respProtocol.setData(list);
		return respProtocol;
	}
	/**
	 *@author: zhanhongtan 
	* @Title: getStatusMessageForJson 
	* @Description: TODO(信息发送状态) 
	* @param @return    设定文件 
	* @return ResponseProtocol    返回类型 
	* @throws
	 */
	@RequestMapping(value="/getStatusMessageForJson", method = RequestMethod.POST)
	public ResponseProtocol getStatusMessageForJson(){
		
		List<Map<String,Object>> list = new ArrayList<>();
		for(Status_Message statusMessage:Status_Message.values()){
			Map<String,Object> map = new HashMap<>();
			map.put("key",statusMessage.name());
			map.put("val",statusMessage.getText());
			list.add(map);
		}
		
		ResponseProtocol respProtocol =  new ResponseJsonProtocol();
		respProtocol.setData(list);
		return respProtocol;
	}
	
	/**
	 *@author: zhanhongtan 
	* @Title: getStatusDutyForJson 
	* @Description: TODO(值班状态) 
	* @param @return    设定文件 
	* @return ResponseProtocol    返回类型 
	* @throws
	 */
	@RequestMapping(value="/getStatusDutyForJson", method = RequestMethod.POST)
	public ResponseProtocol getStatusDutyForJson(){
		List<Map<String,Object>> list = new ArrayList<>();
		for(Status_Duty statusDuty:Status_Duty.values()){
			Map<String,Object> map = new HashMap<>();
			map.put("key",statusDuty.name());
			map.put("val",statusDuty.getText());
			list.add(map);
		}
		
		ResponseProtocol respProtocol =  new ResponseJsonProtocol();
		respProtocol.setData(list);
		return respProtocol;
	}
	
	@RequestMapping(value="/getTypeWarningForJson", method = RequestMethod.POST)
	public ResponseProtocol getTypeWarningForJson(){
		List<Map<String,Object>> list = new ArrayList<>();
		for(Type_Warning obj:Type_Warning.values()){
			Map<String,Object> map = new HashMap<>();
			map.put("key",obj.name());
			map.put("val",obj.getText());
			list.add(map);
		}
		
		ResponseProtocol respProtocol =  new ResponseJsonProtocol();
		respProtocol.setData(list);
		return respProtocol;
	}
	
}
